#include "mj.h"
#include <string>

//麻将打印符号定义
static char* mj_symbols[100] = 
{
	(char*)"err", (char*)"1W",  (char*)"2W",  (char*)"3W",  (char*)"4W",  (char*)"5W",  (char*)"6W",  (char*)"7W",  (char*)"8W",  (char*)"9W",  /* 0~9   */
	(char*)"err", (char*)"err", (char*)"err", (char*)"err", (char*)"err", (char*)"err", (char*)"err", (char*)"err", (char*)"err", (char*)"err", /* 10~19 */
	(char*)"err", (char*)"err", (char*)"err", (char*)"err", (char*)"err", (char*)"err", (char*)"err", (char*)"err", (char*)"err", (char*)"err", /* 20~29 */
	(char*)"err", (char*)"1S",  (char*)"2S",  (char*)"3S",  (char*)"4S",  (char*)"5S",  (char*)"6S",  (char*)"7S",  (char*)"8S",  (char*)"9S",  /* 30~39 */
	(char*)"err", (char*)"err", (char*)"err", (char*)"err", (char*)"err", (char*)"err", (char*)"err", (char*)"err", (char*)"err", (char*)"err", /* 20~29 */
	(char*)"err", (char*)"1T",  (char*)"2T",  (char*)"3T",  (char*)"4T",  (char*)"5T",  (char*)"6T",  (char*)"7T",  (char*)"8T",  (char*)"9T",  /* 50~59 */
	(char*)"err", (char*)"err", (char*)"err", (char*)"err", (char*)"err", (char*)"err", (char*)"err", (char*)"err", (char*)"err", (char*)"err", /* 20~29 */
	(char*)"err", (char*)"Zh",  (char*)"err", (char*)"err", (char*)"err", (char*)"err", (char*)"err", (char*)"err", (char*)"err", (char*)"err", /* 70~79 */
	(char*)"err", (char*)"Fa",  (char*)"err", (char*)"err", (char*)"err", (char*)"err", (char*)"err", (char*)"err", (char*)"err", (char*)"err", /* 80~89 */
	(char*)"err", (char*)"Ba",  (char*)"err", (char*)"err", (char*)"err", (char*)"err", (char*)"err", (char*)"err", (char*)"err", (char*)"err"  /* 90~99 */
};

int Mj:: color()
{
	if ( val >= W1 && val <= W9 ) return 1;
	else if ( val >= S1 && val <= S9 ) return 2;
	else if ( val >= T1 && val <= T9 ) return 3;
	else return 0;
}

string Mj::get_mj()
{
	string string_mj;
	string_mj = mj_symbols[val];
	return  string_mj;
}

Mj Mj::next_fangpai_mj()
{
	int add_val = 0;
	if (val == 0) add_val = 0;
	else if (val == W9) add_val = W1;
	else if (val == S9) add_val = S1;
	else if (val == T9) add_val = T1;
	else add_val = val + 1;	
	Mj mj;
	mj.val = add_val;
	return mj;
}

int Mj::comparemj( Mj m1, Mj m2)
{
    if(m1.val == 0 || m2.val == 0)
    {
    	return -1;
    }
    int a,b,c;
    a=m1.val;
	b=m2.val;
	c=a-b;
	//麻将牌相同 ret 0
    if( a == b)
    {
		return 0;
    }
	
	//两个不同花色的牌
    if( c > 8 || c < -8 )
    {
        return 200;
    }
	//同花色的牌 ret c的值表示两个牌之间的差值
    else
    {
		return c;
    }
}

Mj Mj::operator-(int num)
{
	int color = val % 10;
	int new_val = val - num;
	while(new_val < 1)
	{
		new_val += 9;
	}
	return Mj(color * 10 + new_val);
}

Mj Mj::operator+(int num)
{
	int color = val % 10;
	int new_val = val - num;
	while (new_val > 9)
	{
		new_val -= 9;
	}
	return Mj(color * 10 + new_val);
}





